﻿using System;
using System.IO;
using System.Text;

namespace Core.Framework
{
    public class LoggerUtils
    {
        static object _lock = new object();

        public static void Write(string msg, string filename = "log")
        {
            lock (_lock)
            {
                StreamWriter stream;
                //写入日志内容
                string path = AppDomain.CurrentDomain.BaseDirectory;
                //检查上传的物理路径是否存在，不存在则创建
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                stream = new StreamWriter($"./{filename}.txt", true, Encoding.Default);
                stream.Write(DateTime.Now.ToString() + ":" + msg);
                stream.Write("\r\n");
                stream.Flush();
                stream.Close();
            }
        }

        public static void Write(string title, Exception exception)
        {
            Write($"title:{title},exception:{exception.Message}");
        }
    }
}
